﻿package
{
	/**
	 * 
	 * @author 张峰
	 * @QQ:37520626
	 * @Email:7677@163.com
	 * @Date:2013-2-20 上午9:51:44
	 * 
	 */
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import work.display.SuperMovieClip;
	import work.display.SuperMovieClipEvent;
	
	import zf.data.tools.Memory;
	import zf.display.tools.DisplayObjectTool;
	import zf.display.tools.FPS;
	
	public class SuperMovieClipTest extends SuperMovieClip
	{
		private var path:Vector.<String>;
		private var pic:Sprite;
		private var picList:Array;
		public function SuperMovieClipTest()
		{
			super();
		}
		
		override protected function addStage():void
		{
			picList=new Array();
			pic=new Sprite();
			this.addChild(pic);
			path=new Vector.<String>();
			for(var i:uint=0;i<3;i++)
			{
				path.push("../../../assets/picture/1920_1080_"+i+".jpg");
			}
			this.addEventListener(SuperMovieClipEvent.LOAD_LIST_INIT,onLoadListInitHandler);
			this.addEventListener(SuperMovieClipEvent.LOAD_INIT,onLoadInitHandler);
			
			this.addChild(new FPS());
			for(i=0;i<4;i++)
			{
				this["but_"+i].addEventListener(MouseEvent.CLICK,onClickButHandler);
			}
		}
		private function onClickButHandler(e:MouseEvent):void
		{
			var k:uint=uint(DisplayObjectTool.getDisplayObjectIndex(e.currentTarget));
			switch(k)
			{
				case 0:
					loadDisplay(path[0]);
					break;
				case 1:
					loadDisplayList(path);
					break;
				case 2:
					removePic();
					break;
				case 3:
					trace("gc");
					Memory.gc();
					break;
			}
		}
		private function onLoadListInitHandler(e:SuperMovieClipEvent):void
		{
			var arr:Array=e.data as Array;
			var dp:DisplayObject;
			for(var i:uint=0;i<arr.length;i++)
			{
				dp=arr[i];
				dp.width=192;
				dp.height=108;
				
				dp.x=i*200;
				pic.addChild(dp);
				
				picList.push(dp);
			}
		}
		private function onLoadInitHandler(e:SuperMovieClipEvent):void
		{
			var dp:DisplayObject=DisplayObject(e.data);
			dp.width=192;
			dp.height=108;
			
			dp.y=110;
			pic.addChild(dp);
			
			picList.push(dp);
		}
		private function removePic():void
		{
			for(var i:uint=0;i<picList.length;i++)
			{
				pic.removeChild(picList[i]);
			}
			picList=[];
		}
	}
}